package com.sezi.blog.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.sezi.blog.enumeration.Gender;

/**
 * 用户实体类
 * @author yuanyi
 * @Date 2015-4-16
 * @version 1.0
 */
@Entity
@Table(name="b_user")
public class User {
	/**id*/
	private Long id;
	/**昵称*/
	private String nickName;
	/**登陆账号*/
	private String loginName;
	/**密码*/
	private String passWord = "888888";
	/**电子邮箱*/
	private String email;
	/**生日*/
	private Date birthday;
	/**最后登陆时间*/
	private Date lastLoginDate;
	/**性别*/
	private Gender sex;
	/**头像地址*/
	private String picUrl;
	/**所属角色*/
	private List<Role> roles;
	/**拥有权限*/
	private List<Permission> permissions;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id){
		this.id = id;
	}
	
	@Column(name="nick_name")
	public String getNickName() {
		return nickName;
	}
	
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	
	@Column(name="login_name",unique=true,nullable=false)
	public String getLoginName() {
		return loginName;
	}
	
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	
	@Column(name="password",nullable=false)
	public String getPassWord() {
		return passWord;
	}
	
	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
	
	@Column(unique=true)
	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	
	@Temporal(TemporalType.DATE)
	public Date getBirthday() {
		return birthday;
	}
	
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getLastLoginDate() {
		return lastLoginDate;
	}
	
	public void setLastLoginDate(Date lastLoginDate) {
		this.lastLoginDate = lastLoginDate;
	}
	
	@Enumerated(EnumType.STRING)
	public Gender getSex() {
		return sex;
	}
	
	public void setSex(Gender sex) {
		this.sex = sex;
	}
	
	public String getPicUrl() {
		return picUrl;
	}
	
	public void setPicUrl(String picUrl) {
		this.picUrl = picUrl;
	}
	
	@ManyToMany(mappedBy="users")
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	@ManyToMany(mappedBy="users")
	public List<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}
}
